//package com.hui.config.yj;
//
//import org.springframework.http.HttpMethod;
//import org.springframework.security.authentication.AuthenticationServiceException;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
//import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//public class YjAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
//
//    private String codeParam = "code";
//    private boolean postOnly = true;
//
//    protected YjAuthenticationFilter() {
//        super(new AntPathRequestMatcher("/oauth/acToken", "POST"));
//    }
//
//    @Override
//    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
//        if (postOnly && !request.getMethod().equals(HttpMethod.POST.name())) {
//            throw new AuthenticationServiceException(
//                    "Authentication method not supported: " + request.getMethod());
//        }
//        String code = null == request.getParameter(codeParam) ? "" : request.getParameter(codeParam).trim();
//        YjAuthenticationToken authenticationToken = new YjAuthenticationToken(code);
//        authenticationToken.setDetails(authenticationDetailsSource.buildDetails(request));
//        return this.getAuthenticationManager().authenticate(authenticationToken);
//    }
//
//
//    public String getCodeParam() {
//        return codeParam;
//    }
//
//    public void setCodeParam(String codeParam) {
//        this.codeParam = codeParam;
//    }
//
//    public boolean isPostOnly() {
//        return postOnly;
//    }
//
//    public void setPostOnly(boolean postOnly) {
//        this.postOnly = postOnly;
//    }
//}
